
/* FreeRTOS includes. */
#include "FreeRTOS.h"

/* File system includes. */
#include "fat_sl.h"
#include "api_mdriver_sd.h"

#include "ftp_manager.h"
#include <stdio.h>

#define fsMAX_FILE_NAME_LEN				20

F_FILE *FTPxFile;

void FTP_Open(void)
{
	char cFileName[ fsMAX_FILE_NAME_LEN ];
	
	f_delete("/update.bin");
	
	sprintf( cFileName, "update.bin");
	FTPxFile = f_open( cFileName, "a" );
	configASSERT( FTPxFile );
}
void FTP_File(uint8_t *pBuffer,uint16_t len)
{
	unsigned char ucReturn;
	
	ucReturn = f_write(pBuffer,len,1,FTPxFile);
	configASSERT( ucReturn == 1 );
	/* Close the file. */
}
void FTP_Close(void)
{
	f_close( FTPxFile );
}
uint32_t UpdateFileOpen(void)
{
	char cFileName[ fsMAX_FILE_NAME_LEN ];
	sprintf( cFileName, "/update.bin");
	FTPxFile = f_open( cFileName, "r" );
	return f_filelength( cFileName );
}

uint32_t UpdateFileReadOneKB(uint8_t *pucBuffer)
{
	uint32_t ucReturn;
	
	ucReturn = f_read(pucBuffer,1,1024,FTPxFile);
	configASSERT( ucReturn == 1024 );
	return ucReturn;
}
void UpdateFileClose(void)
{
	f_close( FTPxFile );
}
